/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 26727
 * Date: 2024-04-11
 * Time: 19:06
 */
//413.等差数列划分
public class Solution5 {
    public int numberOfArithmeticSlices(int[] nums) {
        //1.dp表的含义
        int n = nums.length;
        //dp[i]表示以i为结尾的等差数列子数组的个数
        int[] dp = new int[n];
        //2.初始化
        //3.状态转移
        int sum = 0;
        for(int i = 2; i < n; i++) {
            dp[i] = (nums[i-1]-nums[i-2] == nums[i]-nums[i-1]) ? dp[i-1]+1 : 0;
            sum += dp[i];
        }
        //4.填表顺序 从左往右
        //5.返回值 dp表的所有元素和
        return sum;
    }
}
